<?php
declare (strict_types=1);

namespace app\admin\model\base;

use app\BaseModel;

/**
 * 用户公众号记录表
 */
class UserOfficial extends BaseModel
{

    /**
     * 用户第三方公众号记录是否存在
     * @param int $user_id
     * @param string $appid
     * @return bool
     */
    public static function itExist(int $user_id, string $appid): bool
    {
        //查询日志是否存在
        $where = ['user_id' => $user_id, 'appid' => $appid];
        $res = self::findOne($where);
        if ($res) {
            return true;
        }
        return false;
    }

    /**
     * 用户第三方公众号记录写入一次
     * @param int $user_id
     * @param string $appid
     * @param int $third_id
     * @return bool
     */
    public static function oneLogSave(int $user_id, string $appid, int $third_id): bool
    {
        //查询日志是否存在
        $where = ['user_id' => $user_id, 'appid' => $appid];
        $res = self::findOne($where);
        if ($res) {
            return true;
        }
        $where['third_id'] = $third_id;
        $where['create_time'] = time();
        $model = new self();
        $model->save($where);
        return false;
    }

    public static function itSubscribe(int $user_id, string $appid): bool
    {
        //查询日志是否存在
        $where = ['user_id' => $user_id, 'appid' => $appid,'subscribe'=>1];
        $res = self::findOne($where);
        if ($res) {
            return true;
        }
        return false;
    }

}




